<template>
    <el-container class="main-container">
        <!-- 侧边栏 -->
        <el-aside width="200px" class="side-menu">
            <div class="logo-container">
                <img src="@/assets/logo.png" class="logo">
                <span class="system-name">服饰管理系统</span>
            </div>

            <!-- 导航菜单 -->
            <el-menu router :default-active="$route.path" background-color="#fff" text-color="#000"
                active-text-color="#409EFF">
                <el-menu-item index="/admin">
                    <i class="el-icon-s-home"></i>
                    <span>工作台</span>
                </el-menu-item>
                <el-menu-item index="/admin/order">
                    <i class="el-icon-s-home"></i>
                    <span>订单管理</span>
                </el-menu-item>
                <el-submenu index="product">
                    <template slot="title">
                        <i class="el-icon-user-solid"></i>
                        <span>商品管理</span>
                    </template>
                    <el-menu-item index="/admin/product">商品列表</el-menu-item>
                    <el-menu-item index="/admin/category">商品分类</el-menu-item>
                    <el-menu-item index="/admin/comment">评价管理</el-menu-item>
                </el-submenu>
                <el-menu-item index="/admin/carousel">
                    <i class="el-icon-s-cooperation"></i>
                    <span>轮播图管理</span>
                </el-menu-item>
                <el-submenu index="inventory">
                    <template slot="title">
                        <i class="el-icon-user-solid"></i>
                        <span>库存管理</span>
                    </template>
                    <el-menu-item index="/inventory-log">库存日志</el-menu-item>
                    <el-menu-item index="/inventory-adjustment">库存调整</el-menu-item>
                </el-submenu>
            </el-menu>
        </el-aside>

        <el-container>
            <!-- 顶部栏 -->
            <el-header class="header-bar">
                <div class="user-panel">
                    <el-dropdown>
                        <div class="user-info">
                            <!-- <el-avatar :size="40" :src="'http://localhost:8084/api/files/' + user.img"
                :preview-src-list="['http://localhost:8084/api/files/' + user.img]" class="user-avatar" /> -->
                            <span class="user-name">{{ user.name }}</span>
                            <i class="el-icon-caret-bottom"></i>
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item @click.native="$router.push('/detail')">个人中心</el-dropdown-item>
                            <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </el-header>

            <!-- 主内容区 -->
            <el-main class="main-content">
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data() {
        return {

            user: {}
        }
    },
    mounted() {
        const style = document.createElement('style');
        style.innerHTML = `
      .el-submenu__title:hover{
    background-color: #fff !important;
  }
  .el-menu-item{
    border-radius: 10px !important;
    
  }
    `;
        document.head.appendChild(style);
    },
    methods: {
        logout() {
            // 退出登录逻辑
            localStorage.removeItem("user");
            this.$router.push("/login")
        }
    }
}
</script>

<style lang="less" scoped>
.main-container {
    height: 100vh;

    .side-menu {
        background: #fff;
        transition: width 0.3s;

        .logo-container {
            height: 60px;
            display: flex;
            align-items: center;
            padding: 0 15px;
            background: #fff;

            .logo {
                width: 32px;
                height: 32px;
                margin-right: 10px;
                border-radius: 32px;
            }

            .system-name {
                color: #000;
                font-size: 18px;
                font-weight: 600;
            }
        }

        .el-menu {
            border-right: none;

        }
    }

    .header-bar {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0, 21, 41, .08);

        .user-info {
            display: flex;
            align-items: center;
            cursor: pointer;

            .user-avatar {
                margin-right: 10px;
            }

            .user-name {
                margin-right: 8px;
                font-size: 14px;
            }
        }
    }

    .main-content {
        background: #f0f2f5;
        padding: 0px;
        max-height: calc(100vh - 60px);
    }
}

.el-aside {
    padding: 10px;

}

.el-menu-item:focus,
.el-menu-item:hover {
    background-color: #5a9cf8 !important;

    .el-menu-item {
        color: #fff !important;
    }

}

.el-menu-item {
    margin-top: 5px;
}

.el-menu .is-active {
    background-color: #5a9cf8 !important;
    border-radius: 10px;
    color: #fff !important;
}

.el-submenu .el-menu-item {
    min-width: 160px;
    border-radius: 10px;
    margin-top: 5px;
}
</style>